package com.portal.cwegportal.controller;

import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.portal.cwegportal.input.privateconfigure.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/portal/privateconfigure")
@Api(description ="个人配置API")
public class PrivateConfigureController {
    @Autowired
    com.portal.cwegportal.service.PrivateConfigureService privateConfigureService;
/*
    @ApiOperation(value = "创建个人配置", notes = "创建个人配置", produces = "application/json")
    @PostMapping("/createPrivateConfigure")
    public ResponseEntity<JsonResult> createPrivateConfigure(@RequestBody CreatePrivateConfigureInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(privateConfigureService.createPrivateConfigure(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除个人配置", notes = "删除个人配置",produces = "application/json")
    @PostMapping("/deletePrivateConfigure")
    public ResponseEntity<JsonResult> deletePrivateConfigure(@RequestBody DeletePrivateConfigureInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(privateConfigureService.deletePrivateConfigure(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改个人配置", notes = "修改个人配置",produces = "application/json")
    @PostMapping("/editPrivateConfigure")
    public ResponseEntity<JsonResult> editPrivateConfigure(@RequestBody EditPrivateConfigureInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(privateConfigureService.editPrivateConfigure(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索个人配置", notes = "搜索个人配置",produces = "application/json")
    @PostMapping("/getPrivateConfigure")
    public ResponseEntity<JsonResult> getPrivateConfigure(@RequestBody GetPrivateConfiguresInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();

        try {
            r.setResult(privateConfigureService.getPrivateConfigures(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }
    */
    @ApiOperation(value = "查询当前用户的个人配置", notes = "查询当前用户的个人配置",produces = "application/json")
    @PostMapping("/getCurrentUserPrivateConfigure")
    public ResponseEntity<JsonResult> getCurrentUserPrivateConfigure() throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"查询当前用户的个人配置");
        JsonResult r = new JsonResult();

        try {
            r.setResult(privateConfigureService.getCurrentUserPrivateConfigure());
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "保存当前用户的个人配置", notes = "保存当前用户的个人配置",produces = "application/json")
    @PostMapping("/savePrivateConfigure")
    public ResponseEntity<JsonResult> savePrivateConfigure(@RequestBody EditPrivateConfigureInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"保存当前用户的个人配置",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(privateConfigureService.savePrivateConfigure(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }
/*
    @ApiOperation(value = "加载个人配置信息", notes = "加载个人配置信息",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> pageLoad(@RequestBody PageLoadInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(privateConfigureService.pageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    */
}
